package com.sisyphus.spinach.network.views;

import android.content.Context;
import android.widget.Toast;

import com.sisyphus.spinach.core.INetTask;

/**
 * 提示信息
 */
public class SisyphusToast<T> implements INetTask.View<T> {

    private final Context context;

    private final INetTask.View<T> mTaskView;

    public SisyphusToast(Context context) {
        this(context, null);
    }

    public SisyphusToast(Context context, INetTask.View<T> taskView) {
        this.context = context;
        this.mTaskView = taskView;
    }

    @Override
    public void start() {
        if (mTaskView != null) {
            mTaskView.start();
        }
    }

    @Override
    public void complete() {
        if (mTaskView != null) {
            mTaskView.complete();
        }
    }

    @Override
    public void failure(Throwable throwable) {
        if (mTaskView != null) {
            mTaskView.failure(throwable);
        }

        Toast.makeText(context, throwable.getMessage(), android.widget.Toast.LENGTH_SHORT).show();
    }

    @Override
    public void success(T data) {
        if (mTaskView != null) {
            mTaskView.success(data);
        }
    }

}
